package com.jie.scrollviewwithlistview;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2017/4/19.
 */

public class RvAdapter extends RecyclerView.Adapter<RvAdapter.ViewHolder>{
    private Context context;
    private List<String> datas;

    public RvAdapter(Context context, List<String> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_view, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.item_tv.setText(datas.get(position));
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        public View rootView;
        public TextView item_tv;

        public ViewHolder(View rootView) {
            super(rootView);
            this.rootView = rootView;
            this.item_tv = (TextView) rootView.findViewById(R.id.item_tv);
        }

    }

}
